package com.felix.algorithms.tree;

/**
 * MergeTwoBinaryTrees
 *
 * @author xuejinhua
 * @date 2018/9/14 9:43
 */
public class MergeTwoBinaryTrees {

    public TreeNode solution(TreeNode t1, TreeNode t2) {
        if (t2 == null) {
            return t1;
        }
        if (t1 == null) {
            return t2;
        }
        t1.val = t1.val + t2.val;
        t1.left = solution(t1.left, t2.left);
        t1.right = solution(t1.right, t2.right);
        return t1;
    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

}

